<%-- 
    Document   : saveUser
    Created on : Apr 13, 2009, 5:40:19 PM
    Author     : v-lascha
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="com.*" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body bgcolor="#DFDFEA">
        <%
            String u_name = request.getParameter("uname");
            String f_name = request.getParameter("fname");
            String l_name = request.getParameter("lname");
            String _address = request.getParameter("address");
            String _password = request.getParameter("password");

            UserService userservice = (UserService) ServiceFinder.getContext(request).getBean("userservice");
            UserBean userbean = new UserBean();
            userbean.setID(1);
            userbean.setUserName(u_name);
            userbean.setPassword(_password);
            userbean.setFname(f_name);
            userbean.setLname(l_name);
            userbean.setAddress(_address);

            try {
                //check for already exsists users
                boolean isExists = userservice.isUserExists(u_name);
                if (!isExists) {
                    userservice.saveUser(userbean);
                    out.println("<h1>Successfully Saved</h1>");
                    out.println("<h2><a href=\"index.htm\">Go to Login page</a></h2>");
                } else {
                    out.println("<h1>User name is not available</h1>");
                    out.println("<h2>Please select another user name</h2>");
                    out.println("<h2><a href=\"createNew.htm\">Go to Create new account</a></h2>");
                }

            } catch (Exception e) {
                out.println("<h2>" + e.getMessage() + "</h2>");
            }

        %>

        

    </body>
</html>
